﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using API.Models;

namespace API.Constant
{
    public class ReturnStatusConstant
    {
        public string status { get; set; }
        public string errorCode { get; set; }
        public string messages { get; set; }
        public string etoken { get; set; }


        public void InitStatus(ErrorCode errorcode, Status status,MessageResponse messageResponse, string eToken)
        {
           this.errorCode = ErrorCodeToCode(errorcode);
           this.status = StatusToCode(status);
           this.messages = MessageToString(messageResponse);
           this.etoken = eToken;
        }

        public ReturnStatusConstant(ErrorCode errorcode, Status status, MessageResponse message, string etoken)
        {
            InitStatus(errorcode, status,message,etoken);
        }

        public string ErrorCodeToCode(ErrorCode errorcode)
        {
            string result = string.Empty;
            switch (errorcode)
            {
                case ErrorCode.ErrorCodeNone:
                    result = string.Empty;
                    break;
                case ErrorCode.ErrorCodeDataExisted:
                    result = "004";
                    break;
                case ErrorCode.ErrorCodeInvalidEtoken:
                    result = "003";
                    break;
                case ErrorCode.ErrorCodeInvalidPassword:
                    result = "002";
                    break;
                case ErrorCode.ErrorCodeInvalidUserName:
                    result = "001";
                    break;
                default:
                    result = string.Empty;
                    break;
            }
            return result;
        }

        public string StatusToCode(Status status)
        {
            string result = string.Empty;
            switch (status)
            {
                case Status.Faiure:
                    result = "failure";
                    break;
                case Status.Success:
                    result = "success";
                    break;
                default:
                    result = string.Empty;
                    break;
            }
            return result;
        }

        public string MessageToString(MessageResponse message)
        {
            string result = string.Empty;
            switch (message)
            {
                case MessageResponse.MessageDataExisted:
                    result = "dupliate data";
                    break;
                case MessageResponse.MessageInvalidEtoken:
                    result = "invalid etoken";
                    break;
                case MessageResponse.MessageInvalidUser:
                    result = "invalid user";
                    break;
                case MessageResponse.MessageInvalidPassword:
                    result = "invalid password";
                    break;
                case MessageResponse.MessageNone:
                    result = string.Empty;
                    break;
                default:
                    result = string.Empty;
                    break;
            }
            return result;
        }

    }

    public enum ErrorCode
    {
        ErrorCodeNone,
        ErrorCodeInvalidUserName,
        ErrorCodeInvalidPassword,
        ErrorCodeInvalidEtoken,
        ErrorCodeDataExisted
    }

    public enum Status
    {
        Success,
        Faiure
    }

    public enum MessageResponse
    {
        MessageInvalidUser,
        MessageInvalidPassword,
        MessageInvalidEtoken,
        MessageDataExisted,
        MessageNone
    }
}